'use strict';

const Controller = require('egg').Controller;

class HomeController extends Controller {
  async index() {
    // 假如是需要获取用户信息的
    const { ctx } = this;
    const token = this.ctx.cookies.get('token')
    let phone = ''
    this.app.jwt.verify(token, this.app.config.jwt.secret, (err, decoded) => {
      if (err) { // token未提供，token过期
        ctx.response.body = {
          code: 0,
          msg: err.message
        }
      } else {
        phone = decoded.phone
        ctx.response.body = {
          code: 0,
          phone: phone
        }
      }
    })
  }
}

module.exports = HomeController;
